<?php

class Kzend_View_Helper_TransactionToken extends Zend_View_Helper_Abstract
{
	public function transactionToken($formName = null, $hiddenTagOutput = true)
	{
		$hiddenName = "tstoken";
		if($formName != null) {
			$hiddenName = $hiddenName . "_$formName";
		}

		mt_srand((double)microtime() * 1000000);
		$token = md5((string)mt_rand() . "zxTHstFSytDYHA");

		$session = new Zend_Session_Namespace("Kzend_TransactionToken");
		$session->{$hiddenName} = $token;
		
		if($hiddenTagOutput) {
			return '<input type="hidden" name="' . $hiddenName . '" value="' . $token . '" />';
		}
		else {
			return $token;
		}
	}
}
